%{
/*
 * Copyright (c) 2000, Red Hat, Inc.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by DJ Delorie <dj@cygnus.com>
 * Modified by Yospaly, 2008
 *
 */

/* Parse the setup.ini files.  inilex.l provides the tokens for this. */

#include <wx/wx.h>
#include "inibuilder.h"
#include "iniparse.hpp"

extern int yyerror (const char* s);
int yylex ();

#define YYERROR_VERBOSE 1
#define YYINITDEPTH 1000
/*#define YYDEBUG 1*/

IniBuilder *iniBuilder;
extern int yylineno;

void add_correct_version();
%}

%token STRING 
%token SETUP_TIMESTAMP SETUP_VERSION PACKAGEVERSION INSTALL SOURCE SDESC LDESC
%token CATEGORY REQUIRES
%token T_PREV T_CURR T_TEST
%token MD5
%token PACKAGENAME
%token NL AT
%token MESSAGE

%%

whole_file
 : setup_headers packageseparator packages
 ;

setup_headers: /* empty */
 | setup_headers header
 ;
 
header /* non-empty */
 : SETUP_TIMESTAMP STRING { iniBuilder->buildTimestamp ($2); } NL
 | SETUP_VERSION STRING { iniBuilder->buildVersion ($2); } NL
 ;

packages: /* empty */
 | packages package packageseparator
 ;

packageseparator: /* empty */
 | packageseparator NL
 ;
 
package /* non-empty */
 : packagename NL packagedata 
 ;

packagename /* non-empty */
 : AT STRING		{ iniBuilder->buildPackage ($2); }
 | PACKAGENAME STRING	{ iniBuilder->buildPackage ($2); }
 ;

packagedata: /* empty */
 | packagedata singleitem
 ;

singleitem /* non-empty */
 : PACKAGEVERSION STRING NL	{ iniBuilder->buildPackageVersion ($2); }
 | SDESC STRING NL		{ iniBuilder->buildPackageSDesc($2); }
 | LDESC STRING NL		{ iniBuilder->buildPackageLDesc($2); }
 | T_PREV NL            { iniBuilder->buildPackageTrust (IniBuilder::TRUST_PREV); }
 | T_CURR NL            { iniBuilder->buildPackageTrust (IniBuilder::TRUST_CURR); }
 | T_TEST NL            { iniBuilder->buildPackageTrust (IniBuilder::TRUST_TEST); }
 | CATEGORY categories NL
 | INSTALL STRING { iniBuilder->buildPackageInstall ($2); } installmeta NL
 | SOURCE STRING STRING sourceMD5 NL {iniBuilder->buildPackageSource ($2, $3);}
 | REQUIRES versionedpackagelistsp NL
 | MESSAGE STRING STRING NL	{ /* iniBuilder->buildMessage ($2, $3); */ }
 | error 			{ yyerror (wxString::Format(_("unrecognized line %d (do you have the latest setup?)"), yylineno).char_str() );
				}
 ;
 
categories: /* empty */
 | categories STRING		{ iniBuilder->buildPackageCategory ($2); }
 ;

installmeta: /* empty */
 | STRING installMD5		{ iniBuilder->buildInstallSize($1); }
 ;

installMD5: /* empty */
 | MD5 			{ iniBuilder->buildInstallMD5($1);}
 ;

sourceMD5: /* empty */
 | MD5 			{ iniBuilder->buildSourceMD5($1); }
 ;

versionedpackagelistsp: /* non-empty */
 | versionedpackagelistsp STRING 			{ iniBuilder->buildPackageRequire($2); }
 ;
 
%%
